﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MessageProtocol
{
    public class BodyRequest : ISerializable
    {
        public int SCORE;
        public byte[] PLAYER_NAME;
        
        public BodyRequest() { }
        public BodyRequest(byte[] bytes)
        {
            SCORE = BitConverter.ToInt32(bytes, 0);
            PLAYER_NAME = new byte[bytes.Length - sizeof(long)];

            Array.Copy(bytes, sizeof(long), PLAYER_NAME, 0, PLAYER_NAME.Length);
        }

        public byte[] GetBytes()
        {
            byte[] bytes = new byte[GetSize()];
            byte[] temp = BitConverter.GetBytes(SCORE);

            Array.Copy(temp, 0, bytes,0, temp.Length);
            Array.Copy(PLAYER_NAME, 0, bytes, temp.Length, PLAYER_NAME.Length);

            return bytes;

            throw new NotImplementedException();
        }

        public int GetSize()
        {
            return sizeof(long) + PLAYER_NAME.Length;

            throw new NotImplementedException();
        }


        public object GetObject(byte[] bytes)
        {
            throw new NotImplementedException();
        }
    }

    public class BodyResponse : ISerializable
    {
        public uint MSGID;
        public byte RESPONSE;

        public BodyResponse() { }
        public BodyResponse(byte[] bytes)
        {
            MSGID = BitConverter.ToUInt32(bytes, 0);
            RESPONSE = bytes[4];
        }

        public byte[] GetBytes()
        {
            byte[] bytes = new byte[GetSize()];
            byte[] temp = BitConverter.GetBytes(MSGID);

            Array.Copy(temp, 0, bytes, 0, temp.Length);
            bytes[temp.Length] = RESPONSE;

            return bytes;
            throw new NotImplementedException();
        }

        public int GetSize()
        {
            return sizeof(uint) + sizeof(byte);
            throw new NotImplementedException();
        }


        public object GetObject(byte[] bytes)
        {
            throw new NotImplementedException();
        }
    }
}
